PART A - step 1: Setting up the HTML

Since this is just a modest example we don't wish to be too graphic intensive quite yet, so we'll make use of a few bright (arguably blinding) table cell background colors. Form elements are a dime a dozen and they can even be coerced to change state with just a little bit of JavaScript finesse. Throw in a neat little table - complete with Beatnik Player - and you have the layout seen below...

STOP
PLAY
PAUSE

Interacting with the sample, you will notice how there is as yet no connection between the player and the HTML form elements. Take a look at the HTML source code listing for this step. It's not too complex and won't be that much more complex when the connections have been wired in the next step. The main goal is for you to be able to clearly see the mechanics of callbacks in action, in a form that is simple and not obscured by a necessarily more complicated real-life application.

<SCRIPT SRC="music-object.js"></SCRIPT>

<SCRIPT LANGUAGE=JavaScript><!-- //

music = new Music ();

// --></SCRIPT>

<CENTER>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>
   <TR VALIGN=CENTER>
      <TD BGCOLOR=000000 ALIGN=CENTER>
         <SCRIPT LANGUAGE=JavaScript>
            music.magicEmbed (
               'SRC="lounge.rmf" ' +
               'WIDTH=144 ' +
               'HEIGHT=60 ' +
               'DISPLAY=SONG ' +
               'AUTOSTART=FALSE ' +
               'LOOP=FALSE ' +
               'HSPACE=20'
            );
         </SCRIPT>
      </TD>
      <TD VALIGN=CENTER>
         <TABLE HEIGHT=100% BORDER=0 CELLSPACING=0 CELLPADDING=8>
            <FORM NAME="callbackForm">
            <TR>
               <TD BGCOLOR=FF0000>
                  <INPUT
                     TYPE=radio
                     NAME=playState
                     ONCLICK="music.stop ()"
                     CHECKED
                  >
                  <FONT FACE="ARIAL,HELVETICA,VERDANA" COLOR=FFFFFF><B>STOP</B></FONT>
               </TD>
            </TR>
            <TR>
               <TD BGCOLOR=00FF00>
                  <INPUT
                     TYPE=radio
                     NAME=playState
                     ONCLICK="music.play ()"
                  >
                  <FONT FACE="ARIAL,HELVETICA,VERDANA" COLOR=000000><B>PLAY</B></FONT>
               </TD>
            </TR>
            <TR>
               <TD BGCOLOR=FFFF00>
                  <INPUT
                     TYPE=radio
                     NAME=playState
                     ONCLICK="music.pause ()"
                  >
                  <FONT FACE="ARIAL,HELVETICA,VERDANA" COLOR=000000><B>PAUSE</B></FONT>
               </TD>
            </TR>
            </FORM>
         </TABLE>
      </TD>
   </TR>
</TABLE>
</CENTER>
<P>

In the above source code listing, the text that is highlighted represents the code necessary to embed a Beatnik Player using Music Object's magicEmbed method. Using Music Object is necessary since in the next step we will use Music Object methods to set up callbacks from the player in order to 'wire together' the player and the HTML form elements.

NOTE  See how the magicEmbed method has been broken up into multiple lines, with each line concatenating a further piece of the EMBED string. This was only done to avoid the line from scrolling off way to the right in the source code listing, making the source code a little easier to read. It is not necessary to do this in one's real code - the EMBED string can be one solid and unbroken string.